﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/LiberUI/Scripts/laytpl.js"></script>
    }
}

<title>采购应用-收货</title>
<link href="/SiteUI/Purchase/share.css" rel="stylesheet" />
<link href="/SiteUI/Sale/Delivery.css" rel="stylesheet" />
<link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
<link href="/SiteUI/bootstrap-datepicker3.css" rel="stylesheet" />
@section contentnavi{
<div id="appTitle">
    采购应用
</div>
<ul id="slideNavi">
    <li><a class="Lite" href="/Purchase/Inquriy"><i class="icon-063coinyen"></i>询&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价<i class="icon-navigatenext arrow-go"></i></a></li>
    <li class="naviGroup">
        <span>采购订单</span>
        <a class="Lite" href="/Purchase/Orders"><i class="icon-svgorderred"></i>部门订单<i class="icon-navigatenext arrow-go"></i></a>
        <a class="Lite" href="/Purchase/MyOrders"><i class="icon-svgorderred"></i>我的订单<i class="icon-navigatenext arrow-go"></i></a>
    </li>
    <li><a class="Lite" href="/Purchase/Receipt"><i class="icon-jinhuo"></i>收&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;货<i class="icon-navigatenext arrow-go"></i></a></li>
</ul>
}

<div class="col-lg-5 col-lg-offset-6 searchboxWraper">
    <!--搜索框组件容器-->
</div>
<div class="col-lg-10 col-lg-offset-1" id="Receipts">
    <div class="row" id="lstDeliverys">
        <div class="col-lg-12 head">
            <h4>我的收货</h4>
            <span class="cnd-status" status=''>全部</span>
            <span class="cnd-status current" status="Active">未收货</span>
            <span class="cnd-status" status='Completed'>已收货</span>
            <span class="more-filter" id="more-filter">更多筛选条件</span>

        </div>
        <form class="col-lg-12 more-filter-box" id="more-filter-box">
            <button class="more-filter-close" id="more-filter-close" type="button"><i class="soicon icon-highlightremove"></i></button>
            <div class="filter-item">
                <span class="label">供应商：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="supplier"></label>
            </div>
            <div class="filter-item">
                <span class="label">发货人：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="sender"></label>
            </div>
            <div class="filter-item" style="text-align:left;">
                <span class="label">状态：</span>
                <label class="contorl-checkbox">
                    <input type="checkbox" name="status-none">
                    <span>未收货</span>
                </label>
                <label class="contorl-checkbox" name="status-receive">
                    <input type="checkbox">
                    <span>已收货</span>
                </label>
                <label class="contorl-checkbox" name="status-cancel">
                    <input type="checkbox">
                    <span>已作废</span>
                </label>
            </div>
            <div class="filter-item">
                <span class="label">订货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateEnd"></label>
            </div>
            <div class="filter-item">
                <span class="label">发货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateEnd"></label>
            </div>
            <div class="filter-item">
                <span class="label">收货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="receiveDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="receiveDateEnd"></label>
            </div>
            <div class="filter-item">
                <button class="filter-search">筛&nbsp;&nbsp;选</button>
            </div>
        </form>
        <div class="col-lg-12" id="cnd-more">
            <div class="row">
                @*<div class="col-lg-4">
                    <div class="dropdown" id="cnd-more-dlvDate" dlvDate="all">发货日期：全部</div>
                </div>*@
            </div>
        </div>
        <div class="col-lg-12" id="dlv-lstDeliveries">

        </div>
        <div class="col-lg-12" id="dlv-deliveries-Paging"></div>
    </div>
</div>

<ul class="cnd-item" id="cnd-item-dlvDate">
    <li dlvDate="all">全部</li>
    <li dlvDate="thisWeek">本周</li>
    <li dlvDate="thisMonth">本月</li>
</ul>

<!--发货用订单列表模板-->
<script id="tplDeliveryItem" type="text/html">
    <div class="row noItem">
        <div class="col-lg-1 no-row-head">
            <img src='{{d.order.supplier_logo}}' />  <!--买方Logo-->
        </div>
        <div class="col-lg-11 no-row-body">
            <div class="row no-headline">
                <div class="col-lg-4 no-deliveryno">
                    <span>发货编号：</span><span>{{d.idstr}}</span>
                </div>
                <div class="col-lg-5 no-supplier">
                    <span><i class="soicon icon-004office"></i>&nbsp;{{d.order.supplier_realname}}</span>
                </div>
                <div class="col-lg-3">

                    <a class="LinkTo" target="_blank" href="/Trade/DeliveryBillDetail?oid={{d.idstr}}">查看详情>></a>
                </div>
            </div>
            <div class="row no-describe">
                <div class="col-lg-5">
                    <span>交易编号：</span><span>{{d.order.idstr}}</span>
                    <br />
                    <span>内部订单：</span><span>{{d.order.src_orderserial}}</span>
                    <br />
                    <span>采&nbsp;&nbsp;购&nbsp;&nbsp;员：</span><span>{{d.order.buyer}}</span>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>发货日期：</span><span><strong>{{d.createtime}}</strong></span>
                    <br />
                    <span>收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span><span>{{d.order.consignee}}</span>
                    <br />
                    <span>收货日期：</span>
                    <span obj-auth="true" obj-status="Completed">{{d.updatetime}}</span>
                    <br />
                </div>
                <div class="col-lg-3">
                    
                </div>
            </div>
        </div>
    </div>
</script>
<script src="/LiberUI/Scripts/moment.js"></script>
<script src="/LiberUI/Scripts/bootstrap-datepicker.js"></script>
<script src="/LiberUI/Scripts/laytpl.js"></script>
<script>
    Delivery = {
        cnd: {
            status: "all",
            flag: null,
            dlvDate: null
        },
        tplDlvItem: null,
        lstDeliverys: null,
        Query: function (recount) {
          Delivery.lstDeliverys.vl(null)
                               .update()
                               .Loading("正在加载...");
          //$.getJSON("/Sale/GetDeliveryCount", null, Delivery.onCountEnd);
          if (recount) {
              Delivery.cnd.page = 1;
              $.getJSON("/Sale/CountOrders", Delivery.cnd, Delivery.onCountEnd);
          }
          $.getJSON("/Purchase/QueryReceipts", Delivery.cnd, Delivery.onGetDeliveriesEnd);
        },
        onGetDeliveriesEnd:function(rtn){
            if (rtn.IsPositive) {
                Delivery.lstDeliverys.vl(rtn.Data["Deliveries"])
                                     .update()
                                     .show();
            }
        },
        makeDlvItemView: function ($li, obj) {
            obj.createtime=new Date(obj.createtime).toString();
            obj.updatetime =obj.status=='Completed'? new Date(obj.updatetime).toString():'-';
            var itm = $(Delivery.tplDlvItem.render(obj));
            View.CheckAuthor(obj,$li);
            $li.append(itm.addClass("fladeInUp"));
        },
        onCountEnd: function (rtn) {
            //根据统计结果添加计数标记
            if (rtn.IsPositive) {
                Delivery.paging.option("Total", rtn.Data.Total)
                               .option("CurrPage", 1)
                               .update();
            }
            else {
                $("#lstDeliverys>.head").find("em").remove();
            }
        },
        GoPage: function (pg) {
            Delivery.cnd.page = pg;
            Delivery.Query();
        },
        popCndDlvDate: null
    }
    $(function () {
        var navis = $("#slideNavi>li>a");
        for (var i = 0; i < navis.length; i++) {
            if (navis.eq(i).attr("href") == window.location.pathname) {
                navis.eq(i).addClass("current");
                break;
            }
        }
        Delivery.cnd.flag = getUrlParam("flag");
        Delivery.cnd.status = getUrlParam("status") || "Active";

        //Delivery.popCndDlvDate = new LiberUI.PopPanel("#cnd-item-dlvDate")
        //                                    .PopFor("#cnd-more-dlvDate");

        Delivery.tplDlvItem = laytpl($("#tplDeliveryItem")[0].innerHTML);  //定义发货单列表项模板实例
        Delivery.lstDeliverys = new LiberUI.Lister("#dlv-lstDeliveries")
                                           .option("Slctble", false)
                                           .option("ContentRender", Delivery.makeDlvItemView);

        Delivery.paging = new LiberUI.Paging("#dlv-deliveries-Paging")
            .option("Row", 20)
            .option("BtnClick", Delivery.GoPage)
            .show();

        Delivery.Query(true);

        $("#lstDeliverys>.head").delegate(".cnd-status", "click", function (ev) {
            var status = $(ev.currentTarget).attr("status");
            var flag = $(ev.currentTarget).attr("flag");

            Delivery.cnd.status = status || "all";
            Delivery.cnd.flag = flag || "all";
            Delivery.Query();
            $("#lstDeliverys").find(".current").removeClass("current");
            $(ev.currentTarget).addClass("current");
        });

        /*  16/7/28 更多筛选条件 */
        function fillSubmitData(data) {
            Delivery.cnd.supplier = data.eq(0).val();
            Delivery.cnd.sender = data.eq(1).val();
            Delivery.cnd.statusNone = data.eq(2)[0].isChecked;
            Delivery.cnd.statusReceive = data.eq(3)[0].isChecked;
            Delivery.cnd.statusCancel = data.eq(4)[0].isChecked;
            Delivery.cnd.orderDateStart = data.eq(5).val();
            Delivery.cnd.orderDateEnd = data.eq(6).val();
            Delivery.cnd.dlvDateStart = data.eq(7).val();
            Delivery.cnd.dlvDateEnd = data.eq(8).val();
            Delivery.cnd.receiveDateStart = data.eq(9).val();
            Delivery.cnd.receiveDateEnd = data.eq(10).val();
        }
        $('#more-filter-box .date-picker input').datepicker({
            autoclose: true,
            todayHighlight: true,
            format: 'yyyy-mm-dd'
        });
        $('#more-filter').on('click', function () {
            var status = $(this).hasClass('more-filter-open');
            if (status == true) {

                //如果已经展开，触发关闭按钮效果
                $('#more-filter-close').trigger('click');
                return;
            }

            //获取原始高度
            var box = $('#more-filter-box'), boxHeight = box.css('height', 'auto').height();

            //恢复0高度以便动画进行
            box.css('height', '0');

            $(this).addClass('more-filter-open');
            $('#more-filter-box').stop().animate({ height: boxHeight + 20 }, 500); // 20为 more-filter-box padding
        });
        $('#more-filter-close').on('click', function (e) {
            e.preventDefault();
            $('#more-filter-box').stop().animate({ height: 0 }, 500);
            $('#more-filter').removeClass('more-filter-open');

            //清空输入项
            var inputs = $('#more-filter-box').find('input');
            inputs.val('');
            fillSubmitData(inputs);
        });
        $('#more-filter-box').on('submit', function (e) {
            e.preventDefault();

            //筛选条件提交
            fillSubmitData($(this).find('input'));

            Delivery.Query(true);
        });
    })
</script>